package no.ntnu.fp.services.impl;

import java.io.IOException;

import no.ntnu.fp.client.exceptions.NetworkException;
import no.ntnu.fp.messages.Message;
import no.ntnu.fp.messages.impl.AcceptNoticeMessage;
import no.ntnu.fp.messages.impl.NoticeReadMessage;
import no.ntnu.fp.messages.impl.RejectNoticeMessage;
import no.ntnu.fp.model.Notice;
import no.ntnu.fp.net.co.Connection;
import no.ntnu.fp.services.NoticeService;

public class NoticeServiceImpl extends EntityServiceImpl implements NoticeService {

	public NoticeServiceImpl(Connection connection) {
		super(connection);
	}

	@Override
	public void markAsRead(Notice notice) throws IOException {
		Message message = new NoticeReadMessage(notice);
		connection.send(message.toString());
	}

	@Override
	public void acceptNotice(Notice notice) {
		AcceptNoticeMessage message = new AcceptNoticeMessage(notice);
		try {
			connection.send(message.toString());
		} catch (IOException e) {
			throw new NetworkException("Could not send AcceptNoticeMessage", e);
		}
	}

	@Override
	public void rejectNotice(Notice notice) {
		RejectNoticeMessage message = new RejectNoticeMessage(notice);
		try {
			connection.send(message.toString());
		} catch (IOException e) {
			throw new NetworkException("Could not send RejectNoticeMessage", e);
		}
	}
}
